
local function DrawBlood()

	local count = table.Count(HTable)
	if count < 1 then return end

	for i=1,count do
		if HTable[i] then
			if HTable[i].Alpha < 2 then
				HTable[i].Remove = true
			else
				HTable[i].Alpha = math.floor(HTable[i].Alpha / HTable[i].Die)
				surface.SetTexture(surface.GetTextureID(HTable[i].Mat))
				surface.SetDrawColor(250, 10, 10, math.Clamp(HTable[i].Alpha,0,255))
				surface.DrawTexturedRectRotated(HTable[i].X, HTable[i].Y, HTable[i].W, HTable[i].H, HTable[i].Rot)
			end
		end
	end
	for k,v in pairs(HTable) do
		if v.Remove then
			table.remove(HTable,k)
		end
	end
end
hook.Add("HUDPaint","BloodPaint",DrawBlood)

StainMats = {"blood/Blood1",
"blood/Blood2",
"blood/Blood3",
"blood/Blood4",
"blood/Blood5",
"blood/Blood6",
"blood/Blood7",
"blood/Blood8"}

HTable = {}
function AddStain(msg)
	local count = table.Count(HTable) + 1
	local RandomH = ScrH() * math.Rand(0.3,0.6)
	local RandomW = ScrW() * math.Rand(0.3,0.6)
	local RandomX = ScrW() * math.Rand(-0.2,1)
	local RandomY = ScrH() * math.Rand(-0.2,1)
	HTable[count] = {H=RandomH, W=RandomW, X=RandomX, Y=RandomY, Mat=ChooseRandom(StainMats), Die=math.Rand(1.005,1.12), Rot=math.random(0,360), Alpha=math.random(90,180)}
end
usermessage.Hook("BloodStain", AddStain) 